import { projectIslandLogin } from '../../../../api/index'

Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    }
  },
  observers: {},
  data: {
    projectTypes: [
      { label: '我的项目', value: 1 },
      { label: '项目岛', value: 2 }
    ],
    currentItem: {}
  },
  methods: {
    select ({ currentTarget: { dataset: { item } } }) {
      this.setData({ currentItem: item })
    },
    close () {
      this.triggerEvent('close')
    },
    async confirm () {
      try {
        if (this.data.currentItem.value === 2) {
          await projectIslandLogin()
          this.triggerEvent('change', this.data.currentItem)
        } else {
          this.triggerEvent('change', this.data.currentItem)
        }
      } catch (err) {
        wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
      }
    }
  },
  ready () {}
})